function Global_Validate()
{
	this.isEmail = function(id) 
	{
	   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	   var e = document.getElementById(id);
	   if (e && e.value)
	   {
			if( reg.test(e.value) )
			{
				return true;
			}
			e.select();
			e.focus();
	   }
	   return false;
	}

	this.isEmailByString = function(v)
	{
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if( reg.test(v) )
		{
			return true;
		}
		return false;
	}
	
	this.isPhone = function(id)
	{
		var e = document.getElementById(id);
		if (e && e.value)
		{
			var r = e.value.match(/^((\(\+?84\)[\-\.\s]?)|(\+?84[\-\.\s]?)|(0))((\d{3}[\-\.\s]?\d{6})|(\d{2}[\-\.\s]?\d{8}))$/) ;
			if (r){ return true; }
			e.select();
			e.focus();
		}
		return false;
	}

	this.isNumber = function(id)
	{
		var e = document.getElementById(id);
		if (e && e.value)
		{
			if( !isNaN(e.value) )
			{
				return true;
			}
			e.select();
			e.focus();
		}
		return false;
	}
	
	this.isEmbed = function(strEmbed) 
	{
		if(strEmbed.match(/^(<object|OBJECT)*([\s]+.{0,50})+(>)*([\s]+.{0,5000})+(<\/object|OBJECT>)?$/)) {
			return true;
		}
		return false;
	}
	
	this.isAlphabetAndNumber = function(str) 
	{
		var alphaExp = /^[a-zA-Z0-9_]+$/;
		if (str.match(alphaExp)){
			return true;
		}
		return false;
	}
	
	this.ValidateEmail = function(szEmail)
	{
		// chi co 1 ky tu @ o giua, chieu dai username tu 1 den 64 ky tu
		// chieu dai domain tu 1 den 255 ky tu
		if (!szEmail.match(/^[^@]{1,64}@[^@]{1,255}$/))
		{
			return false;
		}

		// chia 2 phan truoc va sau @
		szEmailArray = szEmail.split("@");
		// szEmailArray[0] user, szEmailArray[1] domain

		// phan username, chieu dai tu max 64 ky tu
		// valid character la ky tu chu a-zA-Z, ky tu so 0-9 dash _ hyphen - va dot .
		// neu de trong quote "langxang, at vinacyber dot com dot vn!"@server.com
		// tach cac phan phan chia boi dot .
		szLocalArray = szEmailArray[0].split(".");

		// kiem tra tung phan
		for(i = 0; i < szLocalArray.length; i ++)
		{
			// part 1: neu co dau dash hay hyphen thi khong co o dau va o cuoi
			// part 2: neu khong do dash hay hyphen thi la A-Za-z0-9 chieu dai tu 1 den 64 ky tu
			// part 3: neu trong quote, phan trong quote khong chua \" dau quote hay \\ va back slash
			if (!szLocalArray[i].match(/^(([A-Za-z0-9][A-Za-z0-9_-]{0,62}[A-Za-z0-9])|([A-Za-z0-9]{1,64})|(\"[^(\\|\")]{0,62}\"))$/))
			{
				return false;
			}
		}

		// domain khong phai la IP
		if (!szEmailArray[1].match(/\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/))
		{
			// kiem tra valid domain, tach tung phan domain
			szDomainArray = szEmailArray[1].split(".");
			// it nhat co 2 phan cua domain sau @
			if (szDomainArray.length < 2)
			{
				return false;
			}
	/*hungtm sua phan nay
	24/11/08*/
			else
			{
				//phan sau dot (.) co kich thuoc < 3
				if(szDomainArray[1].length<2)
					return false;
			}/*end hungtm sua*/
			// kiem tra tung phan
			for(i = 0; i < szDomainArray.length; i++)
			{
				// maxinum la 64, chua A-Za-z, 0-9, co the chua hyphen -
				// dau hyphen khong o dau va khong o cuoi, domain case in-sensitive
				// neu khong co hyphen thi la A-Za-z0-9
				if (!szDomainArray[i].match(/^(([A-Za-z0-9][A-Za-z0-9-]{0,62}[A-Za-z0-9])|([A-Za-z0-9]{0,64}))$/))
				{
					return false;
				}
			}

			// kiem tra top domain
			// szDomainArray[szDomainArray.length - 1]
		}
		return true;
	}
	
	this.checkLength	= function(id, min, max)
	{
		var r_min	= true;
		var r_max	= true;
		var e		= document.getElementById(id);
		if(e)
		{
			var l	= e.value.length;
			r_min	= (min && l<min) ? false : true;
			r_max	= (max && l>max) ? false : true;
		}
		
		return r_min&&r_max;
	}
	
	this.isOnlyNumber	= function(e)
	{
		var keyCode		= e.keyCode;

		var E_DOT		= 110 ;
		var E_DOT_		= 190 ;
		var E_TAB		= 9 ;
		var E_backspace	= 8 ;
		var E_Ctrl		= 17 ;
		var E_F5		= 116 ;
		var E_Numlock	= 144 ;
		var E_NumPad_0	= 96 ;
		var E_NumPad_9	= 105 ;
		var E_0			= 48 ;
		var E_9			= 57 ;
		
		if( (keyCode>=E_0 && keyCode<=E_9) || (keyCode>=E_NumPad_0 && keyCode<=E_NumPad_9) || keyCode==E_backspace 
			|| keyCode==E_Ctrl || keyCode==E_F5 || keyCode==E_Numlock || keyCode==E_TAB || keyCode==E_DOT || keyCode==E_DOT_)	
		{
			return true;
		}
		return false;
	}
}

var gValidate = new Global_Validate();